﻿using HandyControl.Data;
using DryWCS.App.View;
using DryWCS.App.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using DryWCS.App.UICore;

namespace DryWCS.App.Common
{
    public enum Notify
    {
        Error,

        Warning,

        Info,

        Question,
    }


    public class Msg
    {

        /// <summary>
        /// 错误
        /// </summary>
        /// <param name="msg"></param>
        public static bool Error(string ex, bool Host = false)
        {
            return Show(Notify.Error, ex, Host);
        }

        /// <summary>
        /// 信息提示
        /// </summary>
        /// <param name="msg"></param>
        public static bool Info(string ex, bool Host = false)
        {
            return Show(Notify.Info, ex, Host);
        }

        /// <summary>
        /// 真香警告
        /// </summary>
        /// <param name="msg"></param>
        public static bool Warning(string ex, bool Host = false)
        {
            return Show(Notify.Warning, ex, Host);
        }

        /// <summary>
        /// 真香询问
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool Question(string ex, bool Host = false)
        {
            return Show(Notify.Question, ex, Host);
        }


        private static bool Show(Notify notify, string msg, bool Host = false)
        {
            string Icon = string.Empty;
            string Color = string.Empty;
            bool Hide = true;

            switch (notify)
            {
                case Notify.Error:
                    Icon = "CommentRemoveOutline";
                    Color = "#FF4500";
                    break;
                case Notify.Warning:
                    Icon = "CommentWarning";
                    Color = "#FF8247";
                    break;
                case Notify.Info:
                    Icon = "CommentProcessingOutline";
                    Color = "#1C86EE";
                    break;
                case Notify.Question:
                    Icon = "CommentQuestionOutline";
                    Color = "#20B2AA";
                    Hide = false;
                    break;
            }

            var result = false;

            Application.Current?.Dispatcher.Invoke(() =>
            {
                var dialog = new MsgBox();
                var viewModel = new MsgBoxViewModel() { Msg = msg, Icon = Icon, Color = Color, BtnHide = Hide };
                dialog.DataContext = viewModel;
                dialog.ShowDialog();
                result = viewModel.Result;
            });

            return result;


        }

        
    }
}
